//
//  NYMyExamineResultCell.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/22.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYMyExamineResultCell.h"
@interface NYMyExamineResultCell ()
@property(nonatomic, strong) TTTAttributedLabel *desLabel;
@property(nonatomic, strong) QMUIGhostButton *analysisBtn;
@end
@implementation NYMyExamineResultCell

+ (CGFloat)heightForObject:(id)object identifier:(NSString *)identifier atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
        return [tableView fd_heightForCellWithIdentifier:identifier cacheByIndexPath:indexPath configuration:^(NYMyExamineResultCell * cell) {
                cell.resModel = object;
        }];
}
- (BOOL)shouldUpdateCellWithObject:(id)object
{
        self.resModel = object;
        return YES;
}
- (void)setResModel:(NYMyExamineResultModel *)resModel
{
        _resModel = resModel;
        [self updateContent];
}
- (void)setupView
{
        [super setupView];
        self.contentView.qmui_borderPosition = QMUIBorderViewPositionBottom;
        self.desLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        self.desLabel.numberOfLines = 0;
        self.analysisBtn = [[QMUIGhostButton alloc] initWithGhostColor:[UIColor whiteColor]];
        self.analysisBtn.backgroundColor = UIColorHex(0x5396FF);
        self.analysisBtn.clipsToBounds  = YES;
        self.analysisBtn.cornerRadius = 3;
        [self.analysisBtn setTitle:@"查看解析" forState:(UIControlStateNormal)];
        self.analysisBtn.userInteractionEnabled = NO;
        self.analysisBtn.titleLabel.font = WGSystem13Font;
        
        [self.contentView addSubview:self.desLabel];
        [self.contentView addSubview:self.analysisBtn];
        
        [self.desLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.contentView).offset(__WGHeight(15));
                make.left.equalTo(self.contentView).offset(__WGHeight(15));
                make.bottom.equalTo(self.contentView).offset(-__WGHeight(15));
        }];
        
        [self.analysisBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.contentView);
                make.top.greaterThanOrEqualTo(self.contentView);
                make.bottom.lessThanOrEqualTo(self.contentView);
                make.height.mas_equalTo(__WGHeight(35));
                make.width.mas_equalTo(__WGWidth(80));
                make.left.greaterThanOrEqualTo(self.desLabel.mas_right).offset(__WGWidth(15));
                make.right.lessThanOrEqualTo(self.contentView).offset(-__WGWidth(15));
        }];
        
}
- (void)updateContent
{
        NSDictionary *norAttr = @{
                                  NSFontAttributeName : WGBoldSystem14Font,
                                  NSForegroundColorAttributeName : UIColorHex(0x333333),
                                  };
        NSDictionary *selAttr = @{
                                  NSFontAttributeName : WGBoldSystem14Font,
                                  NSForegroundColorAttributeName : [UIColor redColor],
                                  };
        NSMutableAttributedString *attrM = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"第%@题，%@人答题，%@人回答正确，正确率%.2f%%，您的答案是：%@，回答",self.resModel.num,self.resModel.user,self.resModel.AnswerRight,self.resModel.CorrectRate.floatValue,self.resModel.UserAnswer] attributes:norAttr];
        [attrM appendAttributedString:[[NSAttributedString alloc] initWithString:NOT_NULL_STRING(self.resModel.row, @"错误") attributes:selAttr]];
//        [attrM appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"，获得：%@分",NOT_NULL_STRING(self.resModel.score, @"0")] attributes:norAttr]];
        self.desLabel.attributedText = attrM;
}
@end
